<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>


    const banner = Array(10).fill().map((_, i) => i) // [0, 1, 2, 3, 4, 5, 6]
    let currentMid = 0;
    const len = banner.length;




  </script>
  <script>



    function debounce(fn, delay) {
      let timer = null;
      return function (...args) {
        if (timer) {
          clearTimeout(timer)
        }
        timer = setTimeout(() => {
          fn.apply(this, args)
        }, delay)
      }
    }


    // 如果传过来是个单数,前面加个0

    function padLeftZero(str) {
      return ('00' + str).substr(str.length)
    };


    // 封装格式化时间正则函数  (时间, '格式化')  
    function formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
      }
      const o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
      }
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
          let str = o[k] + '';
          fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str))
        }
      }
      return fmt
    };



    function getFormat(timer, fmt) {
      return formatDate(new Date(timer || 0), fmt)
    }

    const res = getFormat(Date.now(), 'yy-MM-dd  hh时mm分ss秒')
    const res2 = getFormat(Date.now(), 'yyyy-MM-dd  hh时mm分ss秒')
    console.log(res);
    console.log(res2);
  </script>
</body>

</html>